/**
 * Copyright © 2009 Qasky. All rights reserved.
 *
 * 项目主程序
 *
 * @author Qi Zhang
 * @version 0.0.0 2018/05/27
 *
 * History:
 * (author, date, desc)
 * (Qi Zhang, 20180527, 添加注释)
 */
import './public-path'
import Vue from 'vue'
import routes from './router'
import VueRouter from 'vue-router'
import store from './store/index';
import App from './app.vue';
const {  name  } = require('../package.json')
import Es6Promise from 'es6-promise'
import pick from 'lodash.pick'
/*import 'babel-polyfill'*/
import Antd from 'ant-design-vue/es'
import 'ant-design-vue/dist/antd.less'
import moment from 'moment'
import 'moment/locale/zh-cn'
import Util from '@/libs/util';
import dict from '@/libs/dict';
import plLazy from 'module/plLazy'
Vue.component('pl-lazy', plLazy)
import {loadSysDicts,randerDictText,loadArithmeticSort} from '@/libs/dict';
import { post, get,uploadPost } from './libs/http'
import axios from "axios";
// 判断是否是ie9浏览器，如果是就执行针对ie9的一些兼容性处理
/*promise.polyfill();*/
Vue.use(Antd)
if (document.documentMode && document.documentMode === 9) {
  Util.fixedProblemIE()
}

// 挂载全局
Vue.prototype.hasPermission = Util.hasPermission;    // 权限方法
Vue.prototype.$loadSysDicts = loadSysDicts;    // 加载数据字典
Vue.prototype.randerDictText = randerDictText;
Vue.prototype.$dicts = dict;
Vue.prototype.$uploadPost = uploadPost;
Vue.prototype.$axios = axios;

Vue.prototype.$post = post;
Vue.prototype.$pick= pick;
Vue.prototype.$get = get;

Vue.prototype.$uurl = 'http://127.0.0.1:18801';//本地访问智能密码钥匙
/*import store from './store/index';*/
import { store as commonStore } from 'common'

/*
 * 全局input的小数位数控制指令,先写死4位，
 * 以后有需要，在自己定义传参进来，就行maxNum一样
 *  这里只对iView的Input有效(只对其渲染的原生Input值有效)，InputNumber未匹配
 * */

let instance = null
function render (props = {}) {
    const { container } = props
    const router = new VueRouter({
        routes
    });
    if (window.__POWERED_BY_QIANKUN__) {
        router.beforeEach((to, from,next) => {
            console.log(to.path)
            if (!to.path.includes('/micrApp')) {
                next({
                    path:'/micrApp/'+name+to.path
                })
            } else {
                next()
            }
        })
    }
    
    instance = new Vue({
        router,
        store,
        render: (h) => h(App)
    }).$mount(container ? container.querySelector('#subapp') : '#subapp')
}

if (!window.__POWERED_BY_QIANKUN__) {
    render()
}

export async function bootstrap () {
    console.log('[vue] vue app bootstraped')
}

export async function mount (props) {
    console.log('[vue] props from main framework', props)
    
    commonStore.globalRegister(store, props)
    
    render(props)
}

export async function unmount () {
    instance.$destroy()
    instance.$el.innerHTML = ''
    instance = null
}
